<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('选品库')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.layui-form-radio {margin-top:0}
		.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
		.listext th{background:#eee;color:#3366cc;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}

		tr img{width: 30px !important;height: 30px !important;margin: 0 2px;}
		.ishide{display: none;}
        .bagimg{z-index: 999;max-width:200px;border: 5px solid #23b971}

		.layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}
		.ishide2{display: none;width: 50px;}
	</style>
</head>
<body>
<div class="ishide"><img class="bagimg" src=""/></div>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
		    <div class="panel-header">
		        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
		            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
		                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
		            </a>
		        </div>
		    </div>
		    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
       	<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
   	</div>
    <div class="mid-content">
		<div class="layui-tab layui-tab-brief" lay-filter="demozf" style="margin-top: 0;">
            <ul class="layui-tab-title" >
                <li class="layui-this">已选列表</li>
                <li>待选列表</li>
            </ul>
            <div class="layui-tab-content"></div>
        </div>
		<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	</div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<!-- <div class="layui-btn layui-table-tools importbtn-bg" lay-event="addbtn" shiro:hasPermission="business:productactive:add">
			<i class="dhicon dh-plus"></i> 新增
        </div>
		<div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" shiro:hasPermission="business:productactive:delete">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
        </div> -->

		<div class="layui-btn layui-table-tools importbtn-bg ishide1" lay-event="exportbtn" shiro:hasPermission="business:productactive:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
		<div class="layui-btn layui-table-tools importbtn-bg ishide2" lay-event="exportbtn2" shiro:hasPermission="business:productactive:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>
<!-- 表格操作区 -->
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-danger layui-btn-xs dhicon" onclick="bdbtn('{{d.code}}')" shiro:hasPermission="business:productactive:delete">关联平台编号</a>  
    <!-- <a class="layui-btn layui-btn-danger layui-btn-xs dhicon" onclick="remove('{{d.guid}}','{{d.code}}')" shiro:hasPermission="business:productactive:delete">删除</a>   -->

</script>
<script type="text/html"  id="file2_img">
	{{# if(d.img){ }}
	   <img src="{{d.img}}"/>
	{{# }else{ }}
	{{# } }}
</script>


<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />  
<script th:src="@{/dhecp/js/queryCondition.js}"></script>
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "business/productactive";
	var gridColumns = [[${gridColumns}]], 
		importFields =[[${importFields}]],
		moduleTable =[[${moduleTable}]];
		console.log(gridColumns,importFields,moduleTable)
	/*]]>*/
</script>
<script type="text/javascript">
var element,thStr;
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var $,layer,laydate,form,table,wherestr={};
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
	var vtype=1
	serachRender();//查询条件初始渲染集合
	changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
	$.tablelist.init({
		elem: '#dhtable'
		,modalName: "产品信息"
		,url: prefix + '/list'
		,updateUrl: prefix + "/edit?guid={id}"
		,initSort: {field: 'createTime',type: 'asc'}
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
		,height:'full-80'
		,done:function(){
			firstimg()
		}
	});



	//监听排序事件 
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});

	//监听行双击事件
    table.on('rowDouble(ftable)', function (obj) {
        console.log("===========rowDouble ");
        console.log(obj);
		// window.location.href = "/business/productbasis/edit?guid="+obj.data.guid;
		
		if(vtype==1){
			top.layui.index.openTabsPage(prefix+ "/edit?guid="+obj.data.guid,'选品库已选 - 修改')
		}else{
			top.layui.index.openTabsPage("/business/productbasis/edit?guid="+obj.data.guid+'&enableEdit=0','选品库未选 - 修改')
		}

    });


	// 头部组装切换
	element.on('tab(demozf)', function(elem,a){
        var name=$(elem.elem.context).text()
        if(name==='已选列表'){
            tableUrl1 = prefix + "/list",
            vtype=1
        }else if(name==='待选列表'){
            tableUrl1 = prefix+"/listdx",
            vtype=2
        }
        $.get(prefix+"/switchover",{num:vtype},function(data){
            // 初始化表格
            $.tablelist.init({
                elem: '#dhtable'
                ,url: tableUrl1
                , totalRow: data.totalRow
                , cols: [data.gridBody]
                , toolbar: '#toolbar'
                , defaultToolbar: [{title: '列设置', layEvent: 'fieldSet', icon: 'layui-icon-set'}]
                ,height:'full-80'
                , done: function (res, curr, count) {
                    listData1 = table.cache.dhtable;//每次重载都赋值更新表缓存

                    if(vtype === 1){
                        $('.ishide1').show()
                        $('.ishide2').hide()
                    }else if(vtype === 2){
                        $('.ishide1').hide()
                        $('.ishide2').show()
                    }
                },success:function(a,b,c){
                    console.log(a,b,c,9999)
                }
            });
          
            var cephalosome = document.getElementById("cephalosome");//获取所有的table
			var str = queryCondition(data.fixtype);
			cephalosome.innerHTML = str;
			form.render();
            serachRender()
			setTimeout(() => {firstimg()}, 1000);
        });
    });

	//头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
			case 'addbtn':
					top.layui.index.openTabsPage(prefix+ "/add",'选品库 - 新增')
					break;
	   		case 'exportbtn':
		   		$.ajax({
		   		    url: '/business/productactive/export',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'exportbtn2':
		   		$.ajax({
		   		    url: '/business/productactive/exportdx',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	 	    case 'fieldSet':
 	    		filedSet(moduleTable);
          	break;
 	    };
 	});
 });
 function bdbtn(code){
	layer.open({
    	type: 2,
    	area: [($(window).width() - 400)+'px', ($(window).height() - 200)+'px'],
    	fix: false,//不固定
    	offset: '10%',//距离顶部
    	maxmin: true,//最大最小化
    	shade: 0.3,//遮罩
    	title: '关联平台编号',
    	content: '/hr/amazonshopproduct/bindShop?code='+code,
    	btn: ['保存', '取消'],
    	shadeClose: true,// 弹层外区域关闭
    	success: function(layero, index){
    		// $.each(k_fields,function(i,v){
    		// 	if(v.fieldExceptEdit){
    		// 		if(v.fieldFrontType=='t_date')laydate.render({elem:'.layui-layer #'+v.fields,type:'date',trigger:'click'});
    		// 		if(v.fieldFrontType=='t_datetime')laydate.render({elem:'.layui-layer #'+v.fields,type:'datetime',trigger:'click'});
    		// 	}
    		// })
    	},
    	yes: function(index, layero){
			var res = window["layui-layer-iframe" + index].table.cache.dhtable[0];
			$.operate.post('/hr/amazonshopproduct/editpost', {'infoItems':JSON.stringify(res)} ,function(result){
    			if(result.code==0)layer.close(index);
    		});
    		// var pd=[];
			// pd[0]={};
			// pd[0]["nid"]=nid;
    		// $.each(k_fields,function(i,v){
    		// 	if(v.fieldExceptEdit){
    		// 		if(v.fieldMatched && v.fieldFrontType=='t_dropdown')pd[0][v.fieldMatched]=layero.find('#'+v.fields).val();
    		// 		else pd[0][v.fields]=layero.find('#'+v.fields).val();
    		// 	}
    		// })
			// pd = {'infoItems':JSON.stringify(pd)};//转化为json字符串格式
		    // $.operate.post(moduleUrl+'/xgxxpost', pd, function(res){
		    //     if(res.code == 0){
		    //     	goUrl(moduleUrl+'/edit?nid='+nid);
		    //     }
		    // });
    	}
    });
 }
//通过guid彻底删除
function remove(guid,code){
	if(guid){
		$.operate.remove("该删除无法恢复，请确认？",prefix + "/delete/",{'productActiveItems':JSON.stringify([{'guid':guid,code}])},function(result){
			if(result.code==0){
		        setTimeout(function(){
		            layer.closeAll();
		            table.reload('dhtable');
		        }, 1000);
		    }
		});
	}else{
		if(table.checkStatus('dhtable').data.length>0){
			$.operate.remove("是否彻底删除该"+table.checkStatus('dhtable').data.length+"条产品？",prefix + "/delete/",{'productActiveItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
				if(result.code==0){
			        setTimeout(function(){
			            layer.closeAll();
			            table.reload('dhtable');
			        }, 1000);
			    }
			});
		}else{
			layer.msg("无勾选数据！");
		};
	}
}

</script>
</body>
</html>